<template>
  <div class="search-container">
    <!--搜索历史-->
    <div class="search-history">
      <div class="title">
        <h2>搜索历史</h2>
        <van-icon name="delete" @click="clearHistory"></van-icon>
      </div>
      <div class="search-list">
        <van-tag v-for="(item, index) in historyListData" :key="index" @click="tagClick(item)">{{item}}</van-tag>
      </div>
    </div>
    <!--热门搜索-->
    <div class="search-hot">
      <div class="title">
        <h2>热门搜索</h2>
      </div>
      <div class="search-list">
        <van-tag :class="item.is_hot === 1 ? 'hot' : ''" v-for="(item, index) in hotListData" :key="index" @click="tagClick(item.keyword)">{{item.keyword}}</van-tag>
      </div>
    </div>
  </div>
</template>

<script>
// 加载搜索请求接口
import { PostDeleteData } from '@/request/api'
export default {
  name: 'SearchHistoryHot',
  data () {
    return {}
  },
  props: [
    'historyListData',
    'hotListData'
  ],
  methods: {
    // 点击历史记录搜索
    tagClick (val) {
      // console.log(val)
      this.$emit('tagClick', val)
    },
    // 点击删除历史记录
    clearHistory () {
      PostDeleteData().then(res => {
        if (res.errno === 0) {
          // console.log(res)
          // 弹窗提示
          this.$toast.success('删除成功')
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.search-container{
  padding: 20px 10px;
  background-color: #fff;
  .search-hot{
    margin-top: 30px;
    padding-top: 30px;
    border-top: 1px solid #dfdfdf;
  }
  .title{
    display: flex;
    align-items: center;
    justify-content: space-between;
    h2{
      font-size: 20px;
      color: #333;
    }
    .van-icon{
      font-size: 18px;
      color: #999;
    }
  }
  .search-list{
    margin-top: 15px;
    .van-tag{
      font-size: 13px;
      color: #666;
      margin-bottom: 5px;
      margin-right: 5px;
      line-height: 22px;
      padding: 0 10px;
      background-color: transparent;
      border: 1px solid #dfdfdf;
      border-radius: 5px;
    }
    .hot{
      color: #f00;
      border-color: #f00;
    }
  }
}
</style>
